// service 统一接口
import HYRequest from "./request/request"
import { BASE_URL, TIME_OUT } from "./request/config"
import cache from "@/utils/cache"
const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      const token = cache.getLocation("token")
      if (token) {
        // 携带token 的拦截
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestInterceptorCatch(err) {
      return err
    },
    responseInterceptor: (res) => {
      return res
    }
  }
})

export default hyRequest
